import java.io.File;
import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入扫描路径：");
        String path = scanner.next();
        File root = new File(path);
        if(!root.isDirectory()){
            System.out.println("输入扫描路径有误");
            return;
        }
        System.out.println("输入删除文件关键词：");
        String word = scanner.next();
        scanDir(root,word);
    }
    private static void scanDir(File root, String word){
        File[] ret = root.listFiles();
        if(ret == null) return;
        for(File f : ret){
            //System.out.println("查找目录："+f.getName());
            if(f.isFile()){
                checkDelete(f,word);
            }else {
                scanDir(f,word);
            }
        }
    }

    private static void checkDelete(File f, String word){
        if(!f.getName().contains(word)){
            return;
        }
        System.out.println("当前文件为：" + f.getAbsoluteFile() + "，是否删除：");
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        if(s.equals("是")){
            f.delete();
            System.out.println("删除成功");
            return;
        }
        System.out.println("取消删除");
    }
}
